/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.commands;

import org.eclipse.gef.commands.Command;

import edu.pku.sei.modeler.model.core.MetaNamedElement;

/**
 * @author zl
 *
 */
public class ChangeNameCommand extends Command {
	private MetaNamedElement model;
	private String newName, oldName;

	public ChangeNameCommand(MetaNamedElement model, String newName) {
		super("Change Name");
		this.model = model;
		oldName = model.getName();
		this.newName = newName.trim();
	}

	public boolean canExecute() {
		return model != null;
	}

	public void execute() {
		model.setName(newName);
	}

	public void undo() {
		model.setName(oldName);
	}
}
